package com.services;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import com.Constants;

import model.Cinema;
import model.Seat;

@Stateless
public class SeatsService 
{
	@PersistenceContext(unitName = "cinema-unit")
	private EntityManager em;
	
	public List<Seat> getAllMovies(int userId) 
	{
		Query q = em.createNamedQuery("Seat.findAllUserSold");
		q.setParameter("userId", userId);

		List<Seat> result = q.getResultList();
		
		return result;
	}
	
	public List<Integer> getAllSeatsForProjection(Seat seat) 
	{
		Query q = em.createNamedQuery("Seat.findAllProjectionSold");
		q.setParameter("userId", seat.getUser().getId());
		q.setParameter("projectionId", seat.getProjection().getId());
		List<Integer> result = q.getResultList();
		
		return result;
	}
	
	public String getAllSeatsForProjectionPrice(Seat seat) 
	{
		Query q = em.createNamedQuery("Seat.findSeatsPrice");
		q.setParameter("userId", seat.getUser().getId());
		q.setParameter("projectionId", seat.getProjection().getId());
		String result = q.getSingleResult().toString();
		
		return result;
	}

}
